package com.jeesite.modules.dataScreen.utils;

import cn.hutool.http.Header;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.jeesite.modules.dataScreen.web.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.core.env.Profiles;

/**
 * @author: mumu
 * @date: 2024/6/6 15:37
 */
@Slf4j
public class YgjyHelper {

    // 阳光救援
    public static final String url      = "";
    public static final String username = "重庆高速";
    public static final String PASSWORD = "123qweASD@";

    public static void main(String[] args) {
        System.out.println(getToken());
    }

    public static Result<String> getToken() {
        String     sign     = AESCrypt.createSign();
        String     password = AESCrypt.encryptCBC(PASSWORD, AESCrypt.KEY, AESCrypt.KEY);
        JSONObject jo       = new JSONObject();
        jo.put("username", username);
        jo.put("password", password);
        jo.put("sign", sign);
        log.info("req body {}", jo.toString());

        try {
            String url = "https://sos.02312122.cn:8000/prod-api/jwtLogin";
            // if (SpringUtils.getApplicationContext() != null &&
            //         SpringUtils.getApplicationContext().getEnvironment().acceptsProfiles(Profiles.of("dev"))) {
            //     url = "http://10.1.2.161:8000/jwtLogin";
            // }

            String resp = HttpUtil
                    .createPost(url)
                    .header(Header.CONTENT_TYPE, "application/json")
                    .body(jo.toString())
                    .execute()
                    .body();
            JSONObject respJo = JSONObject.parseObject(resp);

            Result<String> result = new Result<>();
            result.setMessage(respJo.getString("msg"));
            result.setCode(respJo.getInteger("code"));
            result.setResult(String.valueOf(respJo.getOrDefault("token", "")));
            return result;
        } catch (Exception e) {
            return Result.error(e.getMessage(), jo.toString());
        }
    }

}
